import logging
from logging.handlers import RotatingFileHandler
import os

def setup_logging():
    """配置日志系统"""
    LOG_DIR = 'logs'
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)

    # 成功日志配置
    success_logger = logging.getLogger('success_logger')
    success_logger.setLevel(logging.INFO)
    success_handler = RotatingFileHandler(
        os.path.join(LOG_DIR, 'success.log'),
        maxBytes=1*1024*1024,
        backupCount=5,
        encoding='utf-8'
    )
    success_formatter = logging.Formatter('%(asctime)s - %(message)s')
    success_handler.setFormatter(success_formatter)
    success_logger.addHandler(success_handler)

    # 错误日志配置
    error_logger = logging.getLogger('error_logger')
    error_logger.setLevel(logging.ERROR)
    error_handler = RotatingFileHandler(
        os.path.join(LOG_DIR, 'error.log'),
        maxBytes=1*1024*1024,
        backupCount=5,
        encoding='utf-8'
    )
    error_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    error_handler.setFormatter(error_formatter)
    error_logger.addHandler(error_handler)

    return success_logger, error_logger